package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.VaccineMapper;
import com.ayou.eggguard.farm.pojo.Vaccine;
import com.ayou.eggguard.farm.pojo.VaccineRecord;
import com.ayou.eggguard.farm.service.VaccineService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VaccineServiceImpl implements VaccineService {

    @Autowired
    private VaccineMapper vaccineMapper;

    @Override
    public PageBean<Vaccine> getVaccines(Integer pageNum, Integer pageSize, String vaccineNumber) {
        PageBean<Vaccine> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Vaccine> list=vaccineMapper.getVaccines(vaccineNumber);
        Page<Vaccine> p= (Page<Vaccine>) list;
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;
    }

    @Override
    public void add(Vaccine vaccine) {
        vaccineMapper.add(vaccine);
    }

    @Override
    public void delete(Integer id) {
        vaccineMapper.delete(id);
    }

    @Override
    public void update(Vaccine vaccine) {
        vaccineMapper.update(vaccine);
    }

    @Override
    public PageBean<VaccineRecord> getVaccineRecordList(Integer vpageSize, Integer vpageNum, String coopNumber) {
        PageBean<VaccineRecord> pb=new PageBean<>();
        PageHelper.startPage(vpageNum,vpageSize);
        List<VaccineRecord> list=vaccineMapper.getVaccineRecordList(coopNumber);
        Page<VaccineRecord> p= (Page<VaccineRecord>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }
}
